package top.yeyusmile.cxkbox;

import androidx.appcompat.app.AppCompatActivity;

import android.content.res.AssetFileDescriptor;
import android.content.res.AssetManager;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.widget.Button;

import java.io.IOException;
import java.io.InputStream;

/**
 * @author 夜雨
 * @blog https://yeyusmile.top
 * @date 2022-05-06
 */
public class MainActivity extends AppCompatActivity {

    MediaPlayer mp = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        Button j = findViewById(R.id.jbtn);
        Button n = findViewById(R.id.nbtn);
        Button t = findViewById(R.id.tbtn);
        Button m = findViewById(R.id.mbtn);

        Button ngmbtn = findViewById(R.id.ngmbtn);
        Button hhbtn = findViewById(R.id.hhbtn);
        Button aybtn = findViewById(R.id.aybtn);
        Button nhfbtn = findViewById(R.id.nhfbtn);
        Button jntmbtn = findViewById(R.id.jntmbtn);
        Button yhhngmbtn = findViewById(R.id.yhhngmbtn);
        Button esjbtn = findViewById(R.id.esjbtn);
        Button wpdphjbtn = findViewById(R.id.wpdphjbtn);

        Button sunshinejbtn = findViewById(R.id.sunshinejbtn);
        Button hxjhbtn = findViewById(R.id.hxjhbtn);


        Button stopbtn = findViewById(R.id.stopbtn);

        stopbtn.setOnClickListener((v -> {
            if (mp != null) {
                mp.stop();
            }
        }));


        hxjhbtn.setOnClickListener((v -> {
            if (mp != null) {
                mp.stop();
                mp.release();
            }
            mp = MediaPlayer.create(MainActivity.this, R.raw.hxjh);
            mp.start();
        }));

        sunshinejbtn.setOnClickListener((v -> {
            if (mp != null) {
                mp.stop();
                mp.release();
            }
            mp = MediaPlayer.create(MainActivity.this, R.raw.sunshinej);
            mp.start();
        }));



        esjbtn.setOnClickListener((v -> {
            if (mp != null) {
                mp.stop();
                mp.release();
            }
            mp = MediaPlayer.create(MainActivity.this, R.raw.esj);
            mp.start();
        }));

        wpdphjbtn.setOnClickListener((v -> {
            if (mp != null) {
                mp.stop();
                mp.release();
            }
            mp = MediaPlayer.create(MainActivity.this, R.raw.rup);
            mp.start();
        }));


        yhhngmbtn.setOnClickListener((v -> {
            if (mp != null) {
                mp.stop();
                mp.release();
            }
            mp = MediaPlayer.create(MainActivity.this, R.raw.yhhmgn);
            mp.start();
        }));


        jntmbtn.setOnClickListener((v -> {
            if (mp != null) {
                mp.stop();
                mp.release();
            }
            mp = MediaPlayer.create(MainActivity.this, R.raw.jntm);
            mp.start();
        }));

        nhfbtn.setOnClickListener((v -> {
            if (mp != null) {
                mp.stop();
                mp.release();
            }
            mp = MediaPlayer.create(MainActivity.this, R.raw.nhf);
            mp.start();
        }));

        aybtn.setOnClickListener((v -> {
            if (mp != null) {
                mp.stop();
                mp.release();
            }
            mp = MediaPlayer.create(MainActivity.this, R.raw.ay);
            mp.start();
        }));


        ngmbtn.setOnClickListener((v -> {
            if (mp != null) {
                mp.stop();
                mp.release();
            }
            mp = MediaPlayer.create(MainActivity.this, R.raw.ngm);
            mp.start();
        }));

        hhbtn.setOnClickListener((v -> {
            if (mp != null) {
                mp.stop();
                mp.release();
            }
            mp = MediaPlayer.create(MainActivity.this, R.raw.hh);
            mp.start();
        }));


        j.setOnClickListener((v -> {
            if (mp != null) {
                mp.stop();
                mp.release();
            }
            mp = MediaPlayer.create(MainActivity.this, R.raw.j);
            mp.start();
        }));

        n.setOnClickListener((v -> {
            if (mp != null) {
                mp.stop();
                mp.release();
            }
            mp = MediaPlayer.create(MainActivity.this, R.raw.n);
            mp.start();
        }));

        t.setOnClickListener((v -> {
            if (mp != null) {
                mp.stop();
                mp.release();
            }
            mp = MediaPlayer.create(MainActivity.this, R.raw.t);
            mp.start();
        }));

        m.setOnClickListener((v -> {
            if (mp != null) {
                mp.stop();
                mp.release();
            }
            mp = MediaPlayer.create(MainActivity.this, R.raw.m);
            mp.start();
        }));


    }


}